<template>

</template>

<script>
import {defineComponent} from 'vue'

export default defineComponent({
    name: "Index",
    mounted() {

        this.$router.push('/main')
        // 获取存储在本地的account中的token
        let account = JSON.parse(localStorage.getItem('account'))
        let token = account.token
        if (token == null || token === '') {
            // 跳转到登录页面
            this.$router.push('/login')
        }
        // console.log(account)
        // 传入后台检测token是否过期
        this.$request.post('/checkToken', account).then(res => {
            // console.log(res)
            if (res.code === '200') {
                // 没有过期，则登录
                if (account.role === 'manager' || account.role === '管理员') {
                    this.$router.push('/manager')
                } else if (account.role === '商家' || account.role === 'Store') {
                    this.$router.push('/store')
                } else if (account.role === '用户' || account.role === 'user') {
                    this.$router.push('/indexView')
                }
            } else {
                // 过期了，则跳转到登录页面
                this.$router.push('/login')
            }
        })

    }
})
</script>


<style scoped>

</style>